﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using GLIMS.DBUtility;
using System.Xml.Linq;
using System.Data.SqlClient;
using GLIMS.Common;
using System.ServiceModel.Channels;
using System.Collections.Specialized;
using System.Data;

namespace GLIMS.Common.GWF
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class Node
    {
        [WebGet(UriTemplate = "/GetMultiple")]
        public XElement GetMultiple()
        {
            Action<ResponseMessageInfo, SqlCommand> processDelegate = (ResponseMessageInfo res, SqlCommand cmd) =>
            {
                cmd.Initialize(false);
                cmd.CommandText = "SELECT * FROM gwf_Node WHERE NodeFlag >= 1";                
                res.PopulateResponseData(cmd.GetMultiple("gwf_Node"));
            };
            return ProcessRequest.Process(processDelegate);
        }

        public static string GetNodeName(string nodeCode)
        {
            return GWF.DsWorkFlow.Tables["gwf_Node"].Rows.OfType<DataRow>().First(x => x["NodeCode"].ToString() == nodeCode)["NodeName"].ToString();
        }
    }
}